import random, json, pyperclip, os, pyautogui, win32gui, win32con
from threading import Event
from time import sleep, time
from libs import get_image_pos

class AutoOrderActions:
  def __init__(self):
      pass
  
  def start_actions(self):
    sleep(3)
    # 先重置按键
    pyautogui.press('f4')
    sleep(3)
    self.start_dz_order()
    sleep(3)
    self.start_fm_order()
    sleep(3)
    
    
  def start_dz_order(self):
    pyautogui.press('8')
    sleep(2)
    pyautogui.press('9')
    sleep(2)
    pyautogui.press('8')
    sleep(2)
    pyautogui.press('num1')
    sleep(2)
    order_tab_pos = get_image_pos("images_2/order_tab.png")
    while order_tab_pos is None:
      sleep(1)
      order_tab_pos = get_image_pos("images_2/order_tab.png")
    pyautogui.click(order_tab_pos)
    sleep(1)
    pyautogui.click(order_tab_pos)
    sleep(3)
    complete_pos = get_image_pos("images_2/word_dz_order_success.png", confidence = 0.8)
    while complete_pos is None:
      pyautogui.press("2")
      sleep(5)
      complete_pos = get_image_pos("images_2/word_dz_order_success.png", confidence = 0.8)
    
  
  def start_fm_order(self):
    pyautogui.press('7')
    sleep(2)
    pyautogui.press('9')
    sleep(2)
    pyautogui.press('7')
    sleep(2)
    pyautogui.press('6')
    sleep(2)
    peifang_tab_pos = get_image_pos("images_2/peifang_tab.png")
    while peifang_tab_pos is None:
      sleep(1)
      peifang_tab_pos = get_image_pos("images_2/peifang_tab.png")
    pyautogui.click(peifang_tab_pos)
    sleep(1)
    pyautogui.click(peifang_tab_pos)
    sleep(3)
    order_tab_pos = get_image_pos("images_2/order_tab.png")
    while order_tab_pos is None:
      sleep(1)
      order_tab_pos = get_image_pos("images_2/order_tab.png")
    pyautogui.click(order_tab_pos)
    sleep(1)
    pyautogui.click(order_tab_pos)
    sleep(3)
    complete_pos = get_image_pos("images_2/word_fm_order_success.png", confidence = 0.8)
    while complete_pos is None:
      pyautogui.press("2")
      sleep(5)
      complete_pos = get_image_pos("images_2/word_fm_order_success.png", confidence = 0.8)
    
